package com.qidian.mes.qc.controller;

import com.qidian.mes.pojo.Template;
import com.qidian.mes.qc.service.TemplateService;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@CrossOrigin
@RequestMapping("/template")
public class TemplateController {

    @Autowired
    private TemplateService templateService;

    @GetMapping("/get")
    public MESResult get(Long templateId) {
        return templateService.queryById(templateId);
    }

    //分页搜索
    @GetMapping("/list")
    public MESResult list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit, Template template) {
        return templateService.list(page, limit, template);
    }

    //新增模版
    @PostMapping("/save")
    public MESResult save(@RequestBody Template template) {


        return templateService.save(template);
    }

    //编辑模版
    @PutMapping("/update")
    public MESResult update(@RequestBody Template template)  {
        return templateService.update(template);
    }

    @DeleteMapping("/{templateId}")
    public MESResult deleteById(@PathVariable Long templateId) {
        return templateService.deleteByTemplateId(templateId);
    }
    @DeleteMapping("/deletes")
    public MESResult deletesByTemplateId(Long[] templateId) {

        return templateService.deletesByTemplateId(templateId);

    }

}
